﻿namespace Web.Control.WWW.Resources
{
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Lx.Web.Common.ControlsUI;
    using Model.WWW_WWW.Resource;

    /// <summary>
    /// ResourcesPageManage 的摘要说明
    /// </summary>
    public class ResourcesPageManage : BaseControl
    {
        protected int PageID = 0;
        protected string PageTitle = "";
        protected string Desc = "";
        /// <summary>
        /// 学习语言
        /// </summary>
        protected string LearnLan = "";
        /// <summary>
        /// 所用语言
        /// </summary>
        protected string BaseLan = "";
        /// <summary>
        /// 判断是否管理所有学习语言
        /// </summary>
        protected bool AdminAllLearn = false;
        /// <summary>
        /// 判断是否管理所有使用语言
        /// </summary>
        protected bool AdminAllBase = false;
        /// <summary>
        /// 1为修改，－1为添加
        /// </summary>
        protected int SaveType = -1;        
        protected string memberno = "";
        protected override void OnLoad(EventArgs e)
        {
            memberno = HttpContext.Current.User.Identity.Name;
            if (memberno == "")
            {
                Server.Transfer("/User/login.htm?" + Request.Url.AbsoluteUri);
                return;
            }
            //匹配当前会员是否为管理员
            DataSet ds = new DataSet();
            ds.ReadXml(Server.MapPath("/Control/ResourcesRight.xml"));
            DataRow[] drs = ds.Tables[0].Select("M='" + Page.User.Identity.Name + "'");
            if (drs.Length == 0)
            {
                Server.Transfer("/default.htm");
                return;
            }
            //string[] l = null;
            if (drs[0][1].ToString().ToLower().IndexOf("|all|") > -1)
            {
                AdminAllLearn = true;
            }
            else
            {
                AdminAllLearn = false;
                LearnLan = drs[0][1].ToString().Trim('|');
            }

            if (drs[0][2].ToString().ToLower().IndexOf("|all|") > -1)
            {
                AdminAllBase = true;
            }
            else
            {
                AdminAllBase = false;
                BaseLan = drs[0][2].ToString().Trim('|');
            }
            if (!String.IsNullOrEmpty(Request["PageID"]))
            {
                int pageID = int.Parse(Request["PageID"]);
                if (pageID > 0)
                {
                    SaveType = 1;
                    TResourcesPageModel rPage = BLF.WWW_WWW.Resource.Resources.GetResourcesPageByID(pageID);
                    PageTitle = rPage.PageTitle;
                    Desc = rPage.Description;
                    PageID = rPage.PageID;
                    LearnLan = rPage.LanguageLearn;
                    BaseLan = rPage.BaseLanguage;
                    if (!((drs[0][1].ToString().ToLower().IndexOf("|all|") > -1 || drs[0][1].ToString().ToLower().IndexOf("|" + LearnLan + "|") > -1) && (drs[0][2].ToString().ToLower().IndexOf("|all|") > -1 || drs[0][2].ToString().ToLower().IndexOf("|" + BaseLan + "|") > -1)))
                    {
                        Server.Transfer("/default.htm");
                        return;
                    }
                }
                else
                {
                    Server.Transfer("/default.htm");
                    return;
                }
            }
            else
            {
                SaveType = -1;
            }
        }
    }
}